/**
 * Created by duandazhi on 2016/12/19.
 * 订单列表
 */

$(document).ready(function () {
    var goodsIds;
    //审核
    $('#audit_btn').click(function () {
        goodsIds = [];
        var error = true;
        $(".ckSelect").each(function () {
            var check = $(this).is(':checked');
            if (check) {
                if ( !(parseInt($(this).attr("ckAuditResult")) == 80 ||
                    parseInt($(this).attr("ckAuditResult")) == 81 ||
                    parseInt($(this).attr("ckAuditResult")) == 82) ) {
                    error = false;
                    return;
                }
                var _id = $(this).attr("ckId");
                goodsIds.push(_id);
            }
        });
        if (!error) {
            myAlert("只能审核待审核的项");
            return;
        }
        if (goodsIds.length > 1) {
            myAlert("只能选择一项");
            return;
        }
        if (goodsIds.length == 0) {
            myAlert("请至少选择一项");
            return;
        }
        goodsIds1 = goodsIds;
        $("#sentGoods").modal();
    });

    //审核--->确认
    $("#sent").click(function () {
        var modelIds = goodsIds1.join(",");
        $('#sentvalidateForm').isValid(function (result) {
            if (!result) {
                myAlert("还有不符合规定的字段填写，请检查！");
                return;
            }
            $("#sent").addClass('disable_btn');

            $.ajax({
                url: root + 'cms/returnshoprecord/refuseAudit',
                type: 'post',
                data: {
                    id: goodsIds[0],
                    refundAdvice: $("#refundAdvice").val(),
                    refundStatus: $("#refundStatus").val()
                }, success: function (data) {
                    if (data.code == 1) {

                        //页面层-支付宝退款提交
                        if (data.object.length > 30) {
                            layer.open({
                                type: 1,
                                title: true,
                                closeBtn: 0,//不显示关闭按钮
                                shadeClose: true, //开启遮罩关闭
                                content: data.object
                            });
                        }

                        $('#auditAdvice').val('');
                        $('#sentvalidateForm').validator("destroy");
                        goodsIds1.remove(0);
                        dipscontent(getfilter(), contentUrl);
                        $('#sentGoods').modal('hide');
                        $("#sent").removeClass('disable_btn');
                    } else {
                        myAlert(data.message || "审核失败");
                        $("#sent").removeClass('disable_btn');
                    }
                }
            });
        });
    });

});